
/**
 * Module dependencies.
 */

var express = require('express'),
    Resource = require('express-resource'),
    mongoose = require('mongoose');

var app = module.exports = express.createServer();

// Application configuration
// TODO: This should probably be moved to a config file later

var DATABASE_URL = "mongodb://localhost/dizeez";

// Database connections

mongoose.connect(DATABASE_URL);

// Configuration

app.configure(function(){
  app.set('view options', {layout: false});
  app.register('.html', {
    compile: function(str, options){
        return function(locals){
            return str;
        };
    }
  });
  app.set('views', __dirname + '/views');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
  app.use(express.errorHandler());
});

// Main route

app.get('/', function(req, res) {
    res.render('index.html');
});

app.get('/about', function (req, res) {
    res.render('about.html');
});

app.get('/tutorial', function (req, res) {
    res.render('tutorial.html');
});

// Resources

var genes = app.resource('genes', require('./resources/Gene')),
    diseases = app.resource('diseases', require('./resources/Disease')),
    users = app.resource('users', require('./resources/User')),
    games = app.resource('games', require('./resources/Game')), 
    rounds = app.resource('rounds', require('./resources/Round')), 
    actions = app.resource('actions', require('./resources/Action')); 

games.add(rounds);
rounds.add(actions);

// Begin listening

app.listen(80);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
